<?php

use yii\db\Migration;

/**
 * Handles the creation of table `property`.
 */
class m171123_011046_create_property_table extends Migration
{
    /**
     * @inheritdoc
     * `id` int(10) unsigned NOT NULL COMMENT '索引',
     *  `uid` int(11) unsigned NOT NULL COMMENT '用户id',
     *  `house_num` varchar(20) NOT NULL COMMENT '房源编号',
     *  `county` int(1) unsigned NOT NULL COMMENT '县',
     *  `house_type` tinyint(1) unsigned NOT NULL COMMENT '房型',
     *  `house_room` tinyint(1) unsigned NOT NULL COMMENT '室',
     *  `house_hall` tinyint(1) unsigned DEFAULT '0' COMMENT '厅',
     *  `house_health` tinyint(1) unsigned DEFAULT '0' COMMENT '卫',
     *  `house_kitchen` tinyint(1) unsigned DEFAULT '0' COMMENT '厨',
     *  `house_balcony` tinyint(1) unsigned DEFAULT '0' COMMENT '阳台',
     *  `property` tinyint(1) unsigned NOT NULL COMMENT '产权',
     *  `current_layer` tinyint(1) unsigned NOT NULL COMMENT '当前楼层',
     *  `current_total` tinyint(1) unsigned NOT NULL COMMENT '总共楼层',
     *  `addr` varchar(100) NOT NULL COMMENT '地址',
     *  `total_price` float(7,2) unsigned DEFAULT '0.00' COMMENT '总价',
     *  `area` float(5,2) unsigned NOT NULL COMMENT '面积',
     *  `garage` tinyint(1) unsigned DEFAULT '0' COMMENT '车库',
     *  `toward` tinyint(1) unsigned DEFAULT '0' COMMENT '朝向',
     *  `community` varchar(20) DEFAULT '0' COMMENT '小区',
     *  `years` varchar(4) DEFAULT NULL COMMENT '年代',
     *  `decoration` tinyint(1) unsigned DEFAULT '0' COMMENT '装修程度',
     *  `notes` text COMMENT '其它说明',
     *  `maps` varchar(10) DEFAULT NULL COMMENT '地图坐标',
     *  `thumbs` varchar(20) DEFAULT NULL COMMENT '缩略图',
     *  `contacts` varchar(12) NOT NULL COMMENT '联系人',
     *  `tel` varchar(12) NOT NULL COMMENT '联系电话',
     *  `views` int(10) unsigned DEFAULT '0' COMMENT '显示次数',
     *  `is_mass` tinyint(1) DEFAULT NULL,
     *  `created_at` int(10) NOT NULL COMMENT '创建时间',
     *  `updated_at` int(10) NOT NULL COMMENT '更新时间'
     */
    public function up()
    {
        $this->createTable('{{%property}}', [
            'id' => $this->primaryKey(),
            'uid' => $this->integer()->notNull(),
            'house_num' => $this->string(20)->notNull(),
            'county' => $this->smallInteger(2)->notNull(),
            'house_type' => $this->smallInteger(2)->notNull(),
            'house_room' => $this->smallInteger(2)->notNull(),
            'house_hall' => $this->smallInteger(2)->notNull(),
            'house_health' => $this->smallInteger(2)->notNull(),
            'house_kitchen' => $this->smallInteger(2)->notNull(),
            'house_balcony' => $this->smallInteger(2)->notNull(),
            'property' => $this->smallInteger(2)->notNull(),
            'current_layer' => $this->smallInteger(2)->notNull(),
            'current_total' => $this->smallInteger(2)->notNull(),
            'addr' => $this->string()->notNull(),
            'total_price' => $this->float('7,2')->defaultValue(0.00),
            'total_price' => $this->float('5,2')->defaultValue(0),
            'garage' => $this->smallInteger(1)->defaultValue(0),
            'toward' => $this->smallInteger(1)->defaultValue(0),
            'community' => $this->string()->defaultValue(0),
            'years' => $this->string(4),
            'decoration' => $this->smallInteger(1)->defaultValue(0),
            'notes' => $this->text(),
            'maps' => $this->string(),
            'thumbs' => $this->string(),
            'contacts' => $this->string()->notNull(),
            'tel' => $this->string()->notNull(),
            'views' => $this->integer()->defaultValue(0),
            'is_mass' => $this->smallInteger(1),
            'created_at' => $this->integer(10),
            'updated_at' => $this->integer(10),
        ]);
        $this->createIndex('{{%uid}}', '{{%property}}', 'uid', true);
    }

    /**
     * @inheritdoc
     */
    public function down()
    {
        $this->dropTable('{{%property}}');
    }
}
